/*package cn.gzmli.dtt.common.service.log;


import cn.gzmli.dtt.common.annotation.Comment;
import cn.gzmli.dtt.common.annotation.Ignore;
import cn.gzmli.dtt.common.config.cache.Config;
import cn.gzmli.dtt.common.entity.User;
import cn.gzmli.dtt.common.utils.SpringContextUtil;
import org.apache.commons.collections.map.HashedMap;
import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

*//**
 * @Descript 操作日志线程
 * @Author xsx
 * @Date 2018/3/22
 *//*
public class OperatorLogThread implements Runnable{
    private JoinPoint joinPoint;
    private JdbcTemplate jdbcTemplate;

    private Logger logger = Logger.getLogger(OperatorLogHandler.class);

    public OperatorLogThread(JoinPoint joinPoint) {
        this.joinPoint = joinPoint;
    }

    @Override
    public void run() {
        Class controller = joinPoint.getSignature().getDeclaringType();
        try {
            Map<String, Object> map = this.checkOperator(controller, joinPoint.getSignature().getName(), joinPoint.getArgs());
            if (map.get("isAddLog")!=null){
                this.saveLog((Method) map.get("method"));
            }
        } catch (Exception e) {
            logger.error("加入系统操作日志异常", e);
            // TODO SOMETHING
        }
    }

    private Map<String, Object> checkOperator(Class clz, String methodName, Object[] args) throws NoSuchMethodException {
        Map<String, Object> map = new HashMap<>();
        if(args == null || clz == null){
            return null;
        }
        if (clz.getAnnotation(Ignore.class)==null){
            if(!"list".equals(methodName)){
                try {
                    Method method = clz.getMethod(methodName, this.getArgsType(args));
                    if (method.getAnnotation(Ignore.class)==null){
                        map.put("isAddLog", true);
                        map.put("method", method);
                    }
                } catch (NoSuchMethodException e) {
                } catch (SecurityException e) {
                }
            }

        }
        return map;
    }

    private Class[] getArgsType(Object[] args){
        Class[] classes = new Class[args.length];
        try {
            for (int i=0;i<args.length;i++){
                if (args[i].getClass().isAssignableFrom(org.apache.catalina.connector.RequestFacade.class)){
                    classes[i] = HttpServletRequest.class;
                }else if(args[i].getClass().isAssignableFrom(com.alibaba.druid.support.http.WebStatFilter.StatHttpServletResponseWrapper.class)){
                    classes[i] = HttpServletResponse.class;
                }else{
                    classes[i] = args[i].getClass();
                }
            }
        } catch (Exception e) {

        }
        return classes;
    }

    private Map<String, Object> getArgs(HttpServletRequest request){
        Map<String, Object> argsMap = new HashedMap();
        Map<String, String[]> parameterMap = request.getParameterMap();
        for (Map.Entry<String, String[]> entry : parameterMap.entrySet()){
            argsMap.put(entry.getKey(), Arrays.asList(entry.getValue()));
        }
        return argsMap;
    }

    private void saveLog(Method method) throws Exception{
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        User user = Config.getUser(request);
        Comment comment = method.getAnnotation(Comment.class);
        if (comment!=null){
            if (jdbcTemplate==null){
                jdbcTemplate = (JdbcTemplate) SpringContextUtil.getBean("jdbcTemplate");
            }
            InetAddress addr;
            if ("0:0:0:0:0:0:0:1".equals(request.getRemoteHost())){
                addr = InetAddress.getLocalHost();
            }else{
                addr = InetAddress.getByName(request.getRemoteHost());
            }
            final String sql = "INSERT INTO operator_log(name,userId,loginName,userName,url,params,ip) VALUES(?,?,?,?,?,?,?)";
            if(user!=null){
                jdbcTemplate.update(
                        sql,
                        comment.value(),
                        user.getId(),
                        user.getUserName(),
                        user.getName(),
                        request.getRequestURL().toString(),
                        this.getArgs(request).toString(),
                        addr.getHostAddress()
                );
            }else{
                jdbcTemplate.update(
                        sql,
                        comment.value(),
                        0,
                        "未知账号名（会话过期）",
                        "未知用户姓名（会话过期）",
                        request.getRequestURL().toString(),
                        this.getArgs(request).toString(),
                        addr.getHostAddress()
                );
            }

        }
    }
}*/
